<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" import ="java.util.* , entity.* ,dao.* , dao.impl.*"%>
<%
    TopicDao topicDao = new TopicDaoImpl();		//得到主题Dao的实例
    ReplyDao replyDao = new ReplyDaoImpl();		//得到回复Dao的实例
    UserDao userDao = new UserDaoImpl();		//得到用户Dao的实例
    BoardDao boardDao = new BoardDaoImpl();		//得到板块Dao的实例
    int boardID = Integer.parseInt( request.getParameter("boardID")); //取得板块ID
    int p = Integer.parseInt( request.getParameter("page") ); //取得页数
    List listTopic = topicDao.findListTopic(p, boardID); 	//取得该版块的主题列表
    Board board = boardDao.findBoard(boardID);		//取得板块信息
    int prep = p;       //上一页
    int nextp = p;		//下一页
    if(listTopic.size() == 10){
        nextp = p+1;
    }
    if(p>1){
        prep = p-1;
    }

%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>表</title>
    <link rel="stylesheet" href="css/topbar.css">
    <link rel="stylesheet" href="css/list.css">
    <link rel="stylesheet" href="layui/css/layui.css">
</head>
<body>
<div class="main">
    <div class="top">
        <label>校园BBS系统</label>
    </div>
    <%
        if(session.getAttribute("user") == null){
    %>
    <div class="bar"><p>您尚未
        <a href="login.jsp" target="_blank">登录</a>&nbsp;|
        <a href="register.jsp" target="_blank">注册</a>
    </p>
    </div>
    <%
    }
    else{
        User loginUser = (User)session.getAttribute("user");
    %>
    <p class ="bar">
        您好：<%= loginUser.getUName() %>&nbsp;|&nbsp;
        <a href ="login.jsp" target="_blank">登出</a>
    </p>
    <%	} %>

    <div class="post">
        <a href="post.jsp?boardID=<%= boardID %>"><button type="button" class="layui-btn layui-btn-primary layui-btn-radius">发表文章</button></a>
    </div>
    <div class="crumbs">
        	<span class="layui-breadcrumb">
  				<a href="index.jsp"><i class="layui-icon layui-icon-home"></i>&nbsp;论坛主页</a>
<%--  				<a href=""><i class="layui-icon layui-icon-read"></i>&nbsp;灌水乐园</a>--%>
                <a href ="ListServlet?page=1&boardID=<%= boardID %>"><i class="layui-icon layui-icon-read"></i>&nbsp;<%= board.getBoardName() %></a>
<%--  				<a><cite>待定</cite></a>--%>
			</span>
    </div>
    <div class="" style="padding-left: 200px;">
        <a href="list.jsp?page=<%= prep%>&boardID=<%= boardID %>">上一页</a>&nbsp;|
        <a href="list.jsp?page=<%= nextp%>&boardID=<%= boardID %>">下一页</a>
    </div>
    <div class="table-style">
        <table id="table-set" class="layui-table">
            <thead>
            <th></th>
            <th class="article">文章</th>
            <th class="author">作者</th>
            <th class="time">发布时间</th>
            <th class="reply">回复</th>
            </thead>
            <!-- 	主题列表 	 -->
            <%
                for(int i =0; i < listTopic.size() ; i++){
                    Topic topic = (Topic)listTopic.get(i); 	//循环取得主题对象
                    User user = userDao.findUser(topic.getUid()); 	//取得该主题的发布用户

            %>
            <tbody>
            <tr>
                <td><img src="images\<%= boardID%>.jpg" width = "30" height = "30" /></td>
                <td class="article"><a href="detail.jsp?page=1&boardID=<%= boardID %>&topicID=<%= topic.getTopicId()%>"> <%= topic.getTitle() %></a></td>
                <td class="author"><%= user.getUName() %></td>
                <td><%= topic.getPublishTime()%></td>
                <td class="reply"><%= replyDao.findCountReply(topic.getTopicId()) %></td>
            </tr>
            <%
                }
            %>
<%--            <tr>--%>
<%--                <td></td>--%>
<%--                <td class="article">Marcus Aurelius</td>--%>
<%--                <td class="author">Rome</td>--%>
<%--                <td>2020-12-12</td>--%>
<%--                <td class="reply">2</td>--%>
<%--            </tr>--%>
<%--            <tr>--%>
<%--                <td></td>--%>
<%--                <td class="article">Albert Ellis</td>--%>
<%--                <td class="author">New York</td>--%>
<%--                <td>2020-12-12</td>--%>
<%--                <td class="reply">1</td>--%>
<%--            </tr>--%>
<%--            <tr>--%>
<%--                <td></td>--%>
<%--                <td class="article">Marcus Aurelius</td>--%>
<%--                <td class="author">Rome</td>--%>
<%--                <td>2020-12-12</td>--%>
<%--                <td class="reply">2</td>--%>
<%--            </tr>--%>
            </tbody>
        </table>
    </div>

<%--    <div id="demo2" class="page"></div>--%>
</div>
<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript">
    layui.use('element', function(){
        var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

        //监听导航点击
        element.on('nav(demo)', function(elem){
            //console.log(elem)
            layer.msg(elem.text());
        });
    });
    layui.use(['laypage', 'layer'], function(){
        var laypage = layui.laypage
            ,layer = layui.layer;

        // laypage.render({
        //     elem: 'demo2'
        //     ,count: 200
        //     ,theme: '#22d18e'
        // });
    });
</script>
</body>
</html>